﻿using System;
using System.Collections;


namespace Homework3
{ 
  
    abstract class Shape//抽象形状类
    {
        public abstract double area();
        public abstract bool isRight();

    }

    class Rectangle : Shape
    {
        private double length, width;

        public Rectangle(double length, double width)
        {
            Console.WriteLine("已创建一个长为"+length+"宽为"+width+"的长方形");
            this.length = length;
            this.width = width;
        }

        public double Length { get => length; set => length = value; }
        public double Width { get => width; set => width = value; }

        public override double area()
        {
            return length * width;
        }
   
        public override bool isRight()//判断图形合法性
        {
            if (length >= 0 && width >= 0 && length > width) return true;
            else return false;
        }
    }
    class Square : Shape
    {
        private double length;

        public Square(double length)
        {
            Console.WriteLine("已创建一个边长为"+length+"的正方形");
            this.Length = length;
        }

        public double Length { get => length; set => length = value; }

        public override double area()
        {
            return length * length;
        }

        public override bool isRight()//判断图形合法性
        {
            if (length >= 0) return true;
            else return false;
        }
    }
    class Circle : Shape
    {
        private double radius;

        public Circle(double radius)
        {
            Console.WriteLine("已创建一个半径为"+radius+"的圆形");
            this.radius = radius;
        }

        public override double area()
        {
            return Math.PI * radius * radius;
        }

        public override bool isRight()//判断图形合法性
        {
            if (radius >= 0) return true;
            else return false;
        }
    }
    class MainClass
    {

        static void Main(string[] args)
        {
            double sum = 0;//面积之和
            Random random = new Random();
            Shape[] shapes = new Shape[10];
            for (int i = 0; i < 10; i++)
            {
                int j = random.Next(1, 50);
                switch (j % 3)
                {
                    case 0: shapes[i]=new Rectangle(j, j - 1); break;
                    case 1: shapes[i] = new Square(j); break;
                    case 2: shapes[i] = new Circle(j); break;
                    default: break;
                }
            }
            for (int i = 0; i < 10; i++)
            {
                sum += shapes[i].area();
            }
            Console.WriteLine("总面积为:"+ sum);
            Console.ReadKey();
        }
    }
    
}